package com.lanou.elh.sysmanage.authority_management.web.controller;

import com.lanou.elh.sysmanage.authority_management.common.Result;
import com.lanou.elh.sysmanage.authority_management.common.ResultUtil;
import com.lanou.elh.sysmanage.authority_management.entity.Permission;
import com.lanou.elh.sysmanage.authority_management.entity.Role;
import com.lanou.elh.sysmanage.authority_management.entity.RolePerm;
import com.lanou.elh.sysmanage.authority_management.mapper.RoleMapper;
import com.lanou.elh.sysmanage.authority_management.service.RoleService;
import io.swagger.annotations.ApiOperation;
import org.junit.jupiter.api.AfterAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;

   @PostMapping("/admin/addRole")
    @ApiOperation(value = "添加角色")
    public Result addRole(Role role, RolePerm rolePerm,Integer[]rolePermid){
       roleService.addPerm(role,rolePerm,rolePermid);
       return new ResultUtil<>().setData("添加成功");
       }
        @DeleteMapping("/admin/delRole")
    @ApiOperation(value = "删除角色")
       public Result deleteRoleById(Integer id){
           roleService.deleteRoleById(id);
           roleService.deletePermById(id);
        return new ResultUtil<>().setData("删除成功");
    }

    @DeleteMapping("/admin/deleteInBatchesRoleById")
    @ApiOperation(value = "批量删除角色")
    public Result deleteInBatchesRoleById(Integer[] id){
       roleService.deleteInBatchesRoleById(id);
       roleService.deleteInBatchesPermById(id);
       return new ResultUtil<>().setData("删除成功");
    }

    @PutMapping("/admin/updateRoleById")
    @ApiOperation(value = "修改角色")
    public Result updateRoleById(Role role,RolePerm rolePerm,Integer[]rolePermid){
        roleService.updateRoleById(role,rolePerm,rolePermid);
        return new ResultUtil<>().setData("修改成功");
    }

    @GetMapping("/user/selectRole")
    @ApiOperation(value = "查看所有角色")
    public Result<List<Role>> selectRole(){
      List<Role> roleList = roleService.selectRole();
      return new ResultUtil<List<Role>>().setData(roleList);
    }


}
